#include "writeLightAmbient.hpp"
#include "Log.hpp"
using namespace std;
using namespace m3g;


unsigned int writeLightAmbient (M3GWriter* writer, MQScene mq_scene)
{
	int ambient_color = (0                                                << 24) |    // a
                        ((int)(mq_scene->GetGlobalAmbientColor().r * 255) << 16) |    // r
		                ((int)(mq_scene->GetGlobalAmbientColor().g * 255) << 8 ) |    // g
		                ((int)(mq_scene->GetGlobalAmbientColor().b * 255) << 0 );     // b


	M3GObject3DStruct      obj;
	M3GTransformableStruct tra;
	M3GNodeStruct          nod;
	M3GLightStruct         lgh;
	lgh.mode      = M3GLightStruct:: AMBIENT;
	lgh.color     = ambient_color;
	lgh.intensity = 1;

	unsigned int object_index;

	writer->startObject       (M3G_TYPE_LIGHT, &object_index);
	writer->writeObject3D     (obj);
	writer->writeTransformable(tra);
	writer->writeNode         (nod);
	writer->writeLight        (lgh);
	writer->endObject         ();

   	Log:: print (" [%d] Write Light(ambient) :", object_index);
    Log:: print ("  color=0x%08x.\n", ambient_color);

	return object_index;
}